package liumengbaio.lolzhangyoubao.Activity.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import liumengbaio.lolzhangyoubao.Activity.Interface.RelectGetUrl;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/14.
 */
public class RealShowGridViewAdapter extends BaseAdapter {
    private Context mContext;
    private String[] name;
    private String[] index = new String[]{"1", "4", "2", "3"};
    private String[] sex_index = new String[]{"", "1", "2"};
    private RelectGetUrl relectGetUrl;
    private int type;


    public void setOnRelectGetUrl(RelectGetUrl relectGetUrl) {
        this.relectGetUrl = relectGetUrl;
    }

    public RealShowGridViewAdapter(Context mContext, String[] name, int type) {
        this.mContext = mContext;
        this.name = name;
        this.type = type;
    }

    @Override
    public int getCount() {
        return name.length;
    }

    @Override
    public Object getItem(int position) {
        return name[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_real_show_title, null);
            holder.textView = (TextView) convertView.findViewById(R.id.real_show_title_textView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(name[position].trim());
        holder.textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (type) {
                    case 1:
                        if (name[position].trim().equals("全部大区")) {
                            relectGetUrl.relectGetUrl(type,"");
                        } else {
                            relectGetUrl.relectGetUrl(type, name[position].trim());
                        }
                        break;
                    case 2:
                        relectGetUrl.relectGetUrl(type, index[position].trim());
                        break;
                    case 3:
                        relectGetUrl.relectGetUrl(type, sex_index[position].trim());
                        break;
                }

            }
        });
        return convertView;
    }

    public class ViewHolder {
        private TextView textView;
    }
}
